var u = navigator.appVersion;
var uc = u.split('UCBrowser/').length > 1 ? 1 : 0;
var qq = u.split('MQQBrowser/').length > 1 ? 2 : 0;
var wx = ((u.match(/MicroMessenger/i)) && (u.match(/MicroMessenger/i).toString().toLowerCase() == 'micromessenger'));

//下载设置公用配置文件
var film = window.location.pathname.substring(1,window.location.pathname.lastIndexOf("/")),
    film = film.substring(2),qd = getURLParameter('q') || 'zl_1';
//var arr_qd = qd.split('_'),qdname=typeof(arr_qd[0])!='undefined'&&arr_qd[0]?arr_qd[0]:'yrlm',__id=typeof(arr_qd[1])!='undefined'&&arr_qd[1]?arr_qd[1]:1;
var arr_qd = qd.split('_');
var qdname=typeof(arr_qd[0])!='undefined'&&arr_qd[0]?arr_qd[0]:'zl';
//var qdplan=typeof(arr_qd[1])!='undefined'&&arr_qd[1]?arr_qd[1]:1;
//var film=typeof(arr_qd[2])!='undefined'&&arr_qd[2]?arr_qd[2]:1;
var qdid=typeof(arr_qd[1])!='undefined'&&arr_qd[1]?arr_qd[1]:5;
var arr_qdid = qdid.split('-');
qdid = isNaN(arr_qdid[0]) ? 5 : arr_qdid[0];
var uuid =isNaN(arr_qdid[1]) ? '' : "-"+arr_qdid[1];

if(getURLParameter('jumpqd')&&getURLParameter('jumpqdid')){
    qdname=getURLParameter('jumpqd');
//	 qdplan=getURLParameter('jumpqdplan');
//	 film=getURLParameter('jumpfilm');
    qdid=getURLParameter('jumpqdid');
}

qd=qdname+'_'+parseInt(qdid)+uuid;

$(document).ready(function(){

    $.ajax({
        type:"GET",
        url:"/autopack?q="+qd,
        //dataType:"txt",
        success:function(data){
            console.log(data)
        },
        error:function(jqXHR){
            console.log(jqXHR);
        }
    });
});



var rdNum=parseInt(Math.random()*1000000)
var androidDownUrl =  'http://zljy.wanaiyijia.cn:9786/' + qd + '/';
var iosDownUrl = "https://apps.apple.com/cn/app/id1539383426"
var iosCopyCode = "code:688&channel:" + qd;
var isClick = false;

function getURLParameter(name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}






$(document).ready(new function () {
    $(".container").show();
    addData()
    $("div.lazyload").lazyload({
        effect: 'fadeIn',
        threshold: '200',
        failure_limit: '10'
    })
    stopBack();

    if (sysTemInfo() == 'ios') {
        var data = ShareInstall.parseUrlParams();
        data.q = "IOS" + data.q;
        openObj = new ShareInstall({
            // preferWakeup: true,
            preferWakeup: true,
            // 可选参数，唤醒操作的执行时长，超时后将放弃唤醒并执行下载，默认1500，单位是毫秒
            timeout: 1500,
            appKey: '7AB2HRKFAFHAHK',
            onready: function () {

            }
        }, data);
        /*var OpenInstallData = OpenInstall.parseUrlParams();
        openObj=new OpenInstall({
            1: "t3wjt6",
            onready: function() {
                openObj.schemeWakeup();
            }
        }, OpenInstallData);*/
    }
    iswx();
});

function iswx() {
    console.log(sysTemInfo())
    if (sysTemInfo() == 'ios') {
        if (wx) {
            $(".wechat").append('<img src="../image/tips_weixin_ios.png" alt="点击右上角，然后选择浏览器打开！"/>');
            $(".wechat").show()
            return false;
        }
    } else {
        if (wx) {
            $(".wechat").append('<img src="../image/tips_weixin_android.png" alt="点击右上角，然后选择浏览器打开！"/>');
            $(".wechat").show()
            return false;
        }
    }
}

function addData() {
    /*
    *   轮播图
    * */
    for (let i = 0; i < dataList.bannerArry.length; i++) {
        $(".banner").append(
            '<div class="banner_item zdownload"  onclick="download()"><img src="' + dataList.bannerArry[i].cover + '" class="banner_item_img lazyload data-lazy">' +
            '<div class="banner_item_bg">' +
            '<div class="banner_item_text">' + dataList.bannerArry[i].title + '</div>' +
            '</div>' +
            '</div> ')
    }
    initLoopTop();

    /*part2*/
    for (var i = 0; i < dataList.actorArry.length; i++) {
        $(".head_liu").append(
            '<div class="swiper-wrapper head_liu_item" >\n' +
            '        <div class="swiper-slide">\n' +
            '                <img src="' + dataList.actorArry[i].cover + '" class="zdownload lazyload data-lazy"  onclick="download()">\n' +
            '                <div class="head_liu_item_titel">' + dataList.actorArry[i].name + '</div>\n' +
            '          </div>\n' +
            '</div>')
    }
    initLoopheadLiu();

    /*
    *   稀有
    * */

    for (let i = 0; i < dataList.rareVideoArry.length; i++) {
        $(".scarce_content").append(
            '<div class="scarce_item">' +
            '<img data-lazy-src="' + dataList.rareVideoArry[i].cover + '" class="scarce_item_img lazyload zdownload data-lazy"  onclick="download()">' +
            '<div class="banner_item_text">' + dataList.rareVideoArry[i].title + '</div>' +
            '</div>')
    }

    swiper1()
    /*
    *   今日影片 大视频
    * */
    $(".upnew_content_top").append(
        '<img data-lazy-src="' + dataList.newBigVideo.cover + '" class="lazyload zdownload data-lazy"  onclick="download()"/>' +
        '<div class="upnew_content_top_text">' + dataList.newBigVideo.title + '</div>'
    )

    /*
    *   今日影片 小视频
    * */

    for (let i = 0; i < dataList.newSmallVideo.length; i++) {
        $(".upnew_content_bottom").append(
            '<div class="upnew_content_bottom_item">' +
            '<img data-lazy-src="' + dataList.newSmallVideo[i].cover + '" class="upnew_content_bottom_item_img lazyload zdownload data-lazy" onclick="download()">' +
            '<div class="upnew_content_bottom_text">' + dataList.newSmallVideo[i].title + '</div>' +
            '</div>')
    }
    swiper2()

    /*
    *  必看影片 大视频
    * */

    $(".mustsee_content_top").append(
        '<img data-lazy-src="' + dataList.newBigVideo.cover + '" class="lazyload zdownload data-lazy" onclick="download()" />' +
        '<div class="upnew_content_top_text">' + dataList.newBigVideo.title + '</div>'
    )

    for (let i = 0; i < dataList.hotFiml.length; i++) {
        $(".mustsee_content_bottom").append(
            '<div class="mustsee_content_bottom_item">' +
            '<img data-lazy-src="' + dataList.hotFiml[i].cover + '" class="mustsee_content_bottom_item_img lazyload zdownload" onclick="download()">' +
            '<div class="mustsee_content_bottom_item_text">' + dataList.hotFiml[i].title + '</div>' +
            '</div>')
    }
    swiper3()
}

function initLoopTop() {
    LoopSlider.init({
        el: ".banner", //选择器
        navigator: {
            //前进后退按钮
            prevEl: ".prev",
            nextEl: ".next"
        },
        easing: "ease", //动画效果cubic-bezier(0.985, -0.060, 0.000, 1.320)
        duration: 600, //过渡时间，默认为3000ms,
        autoplay: 3000, //boolean 和 number 设置为true 默认延时为3s,如果设置为1000，延时为1s
    })
}

function initLoopheadLiu() {
    new Swiper('.head_liu', {
        loop: false, // 循环模式选项
        // slide的切换效果，默认为"slide"（位移切换），可设置为'slide'（普通切换、默认）,"fade"（淡入）"cube"（方块）"coverflow"（3d流）"flip"（3d翻转）。
        speed: 1000,
        autoplay: {
            delay: 4000,
        },
        effect: 'slide',
        slidesPerView: 3,// 设置slider容器能够同时显示的slides数量(carousel模式)
        disableOnInteraction: true,
        centeredSlides: false, // 设定为true时，active slide会居中，而不是默认状态下的居左。
        coverflowEffect: {
            rotate: 0,
            stretch: 0, // 指的时后面一张图片被前一张图片遮挡的部分
            depth: 160, // 图片缩小的部分
            modifier: 3
        },
        lazyLoading: true,
        paginationClickable: true,
    })
}
function initData() {
    $('.wechat').bind('click', function () {
        $('.wechat').hide()
    });
}

function swiper1() {
    new Swiper('.scarce_content', {
        paginationClickable: true,
        autoplay: 4000,
        loop: true,
        lazyLoading: true
    });
}

function swiper2() {
    new Swiper('.upnew_content_bottom', {
        slidesPerView: "auto",
        paginationClickable: true,
        spaceBetween: 30,
        autoplay: 3000,
        loop: true,
        lazyLoading: true
    });
}

function swiper3() {
    new Swiper('.mustsee_content_bottom', {
        slidesPerView: "auto",
        paginationClickable: true,
        spaceBetween: 30,
        autoplay: 3000,
        loop: true,
        lazyLoading: true
    });
}

function download() {
    console.log(sysTemInfo())
    if (sysTemInfo() == 'ios') {
        copy();
        if (wx) {
            $(".wechat").append('<img src="../image/tips_weixin_ios.png" alt="点击右上角，然后选择浏览器打开！"/>');
            $(".wechat").show()
            return false;
        }
    } else {
        if (wx) {
            $(".wechat").append('<img src="../image/tips_weixin_android.png"  alt="点击右上角，然后选择浏览器打开！"/>');
            $(".wechat").show()
            return false;
        }
        window.location.href = androidDownUrl;
    }
}

function sysTemInfo() {
    var us = navigator.userAgent.toLowerCase(), system = {}, p = navigator.platform;
    system.win = p.indexOf("Win") == 0;
    system.mac = p.indexOf("Mac") == 0;

    if (us.indexOf('iphone') > -1 || us.indexOf('ipad') > -1) {
        return 'ios';
    } else if ((us.indexOf('android') > -1 || us.indexOf('linux') > -1) || navigator.platform.toLowerCase().indexOf('linux') != -1) {
        return 'android'
    }
}

//浏览器禁止返回
function stopBack() {
    if (window.history && window.history.pushState) {
        $(window).on('popstate', function () {
            window.location.href = location.href;
        });
    }
    window.history.pushState('forward', null, '');
    window.history.forward(1);
}

function copy() {
    var clipboard = new ClipboardJS('.cofuz', {
        text: function () {
            return iosCopyCode;
        }
    });
    clipboard.on('success', function (e) {
        window.location.href = iosDownUrl;
    });
    clipboard.on('error', function (e) {
        window.location.href = iosDownUrl;
    });
}